package Yki.PaperPlaneClient.Adapter;

import java.util.List;
import java.util.Map;

import Yki.PaperPlaneClient.R;
import Yki.PaperPlaneClient.XML.XMLUtils;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class LetterListAdapter extends BaseAdapter {
	private List<Map<String, Object>> mPlanes;
	private Context mContext;
	public LetterListAdapter(Context context,List<Map<String, Object>> planes) {
		// TODO Auto-generated constructor stub
		mPlanes = planes;
		mContext = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		//return mPlanes.size();
		if (mPlanes == null ) {
			return 0;
		}
		else {
			return mPlanes.size();
		}
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View view = LayoutInflater.from(mContext).inflate(R.layout.letter_list_item, null);
		
		TextView name = (TextView) view.findViewById(R.id.list_name);
		TextView date = (TextView) view.findViewById(R.id.list_date);
		TextView message = (TextView) view.findViewById(R.id.list_message);
		name.setText((String)mPlanes.get(position).get(XMLUtils.TAG_SENDER_NAME));
		date.setText((String)mPlanes.get(position).get(XMLUtils.TAG_DATE));
		message.setText((String)mPlanes.get(position).get(XMLUtils.TAG_MESSAGE));

		return view;
		//return null;
	}
	
}